QuickOPC User's Guide and Reference
Examples - OPC Unified Architecture - Read a single attribute of a single node

.NET 

// This example shows how to read and display data of an attribute (value, timestamps, and status code).

using System;
using OpcLabs.EasyOpc.UA;
using OpcLabs.EasyOpc.UA.OperationModel;

namespace UADocExamples._EasyUAClient
{
    partial class Read
    {
        public static void Main1()
        {
            UAEndpointDescriptor endpointDescriptor =
                "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer";
            // or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            // or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            // Instantiate the client object.
            var client = new EasyUAClient();

            // Obtain attribute data. By default, the Value attribute of a node will be read.
            UAAttributeData attributeData;
            try
            {
                attributeData = client.Read(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853");
            }
            catch (UAException uaException)
            {
                Console.WriteLine($"*** Failure: {uaException.GetBaseException().Message}");
                return;
            }

            // Display results
            Console.WriteLine($"Value: {attributeData.Value}");
            Console.WriteLine($"ServerTimestamp: {attributeData.ServerTimestamp}");
            Console.WriteLine($"SourceTimestamp: {attributeData.SourceTimestamp}");
            Console.WriteLine($"StatusCode: {attributeData.StatusCode}");

            // Example output:
            //
            //Value: -2.230064E-31
            //ServerTimestamp: 11/6/2011 1:34:30 PM
            //SourceTimestamp: 11/6/2011 1:34:30 PM
            //StatusCode: Good
        }
    }
}
# This example shows how to read and display data of an attribute (value, timestamps, and status code).

#requires -Version 5.1
using namespace OpcLabs.EasyOpc.UA
using namespace OpcLabs.EasyOpc.UA.OperationModel

# The path below assumes that the current directory is [ProductDir]/Examples-NET/PowerShell/Windows .
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUA.dll"
Add-Type -Path "../../../Components/Opclabs.QuickOpc/net472/OpcLabs.EasyOpcUAComponents.dll"

[UAEndpointDescriptor]$endpointDescriptor =
    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
# or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
# or "https://opcua.demo-this.com:51212/UA/SampleServer/"

# Instantiate the client object.
$client = New-Object EasyUAClient

# Obtain attribute data. By default, the Value attribute of a node will be read.
try {
    $attributeData = $client.Read($endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853")
}
catch [UAException] {
    Write-Host "*** Failure: $($PSItem.Exception.GetBaseException().Message)"
    return
}

# Display results
Write-Host "Value: $($attributeData.Value)"
Write-Host "ServerTimestamp: $($attributeData.ServerTimestamp)"
Write-Host "SourceTimestamp: $($attributeData.SourceTimestamp)"
Write-Host "StatusCode: $($attributeData.StatusCode)"


# Example output:
#
#Value: -2.230064E-31
#ServerTimestamp: 11/6/2011 1:34:30 PM
#SourceTimestamp: 11/6/2011 1:34:30 PM
#StatusCode: Good

# This example shows how to read and display data of an attribute (value, timestamps, and status code).

# The QuickOPC package is needed. Install it using "pip install opclabs_quickopc".
import opclabs_quickopc

# Import .NET namespaces.
from OpcLabs.EasyOpc.UA import *
from OpcLabs.EasyOpc.UA.OperationModel import *


# Instantiate the client object.
client = EasyUAClient()

# Obtain attribute data. By default, the Value attribute of a node will be read.
try:
    attributeData = IEasyUAClientExtension.Read(client,
UAEndpointDescriptor('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer'),
UANodeDescriptor('nsu=http://test.org/UA/Data/ ;i=10853'))
except UAException as uaException:
    print('*** Failure: ' + uaException.GetBaseException().Message)
    exit()

# Display results.
print('Value: ', attributeData.Value)
print('ServerTimestamp: ', attributeData.ServerTimestamp)
print('SourceTimestamp: ', attributeData.SourceTimestamp)
print('StatusCode: ', attributeData.StatusCode)


# Example output:
#
#Value: -2.230064E-31
#ServerTimestamp: 11/6/2011 1:34:30 PM
#SourceTimestamp: 11/6/2011 1:34:30 PM
#StatusCode: Good

' This example shows how to read and display data of an attribute (value, timestamps, and status code).

Imports OpcLabs.EasyOpc.UA
Imports OpcLabs.EasyOpc.UA.OperationModel

Namespace _EasyUAClient
    Friend Class Read
        Public Shared Sub Main1()

            ' Define which server we will work with.
            Dim endpointDescriptor As UAEndpointDescriptor =
                    "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
            ' or "http://opcua.demo-this.com:51211/UA/SampleServer" (currently not supported)
            ' or "https://opcua.demo-this.com:51212/UA/SampleServer/"

            ' Instantiate the client object
            Dim client = New EasyUAClient()

            ' Obtain attribute data. By default, the Value attribute of a node will be read.
            Dim attributeData As UAAttributeData
            Try
                attributeData = client.Read(endpointDescriptor, "nsu=http://test.org/UA/Data/ ;i=10853")
            Catch uaException As UAException
                Console.WriteLine("*** Failure: {0}", uaException.GetBaseException.Message)
                Exit Sub
            End Try

            ' Display results
            Console.WriteLine("Value: {0}", attributeData.Value)
            Console.WriteLine("ServerTimestamp: {0}", attributeData.ServerTimestamp)
            Console.WriteLine("SourceTimestamp: {0}", attributeData.SourceTimestamp)
            Console.WriteLine("StatusCode: {0}", attributeData.StatusCode)

            ' Example output:
            '
            'Value: -2.230064E-31
            'ServerTimestamp: 11/6/2011 1:34:30 PM
            'SourceTimestamp: 11/6/2011 1:34:30 PM
            'StatusCode: Good
        End Sub
    End Class
End Namespace

COM 

// This example shows how to read and display data of an attribute (value, timestamps, and status code).

#include "stdafx.h"    // Includes "QuickOpc.h", and other commonly used files
#include "Read.h"

namespace _EasyUAClient
{
    void Read::Main()
    {
        // Initialize the COM library
        CoInitializeEx(NULL, COINIT_MULTITHREADED);
        {
            // Instantiate the client object
            _EasyUAClientPtr ClientPtr(__uuidof(EasyUAClient));

            // Obtain attribute data. By default, the Value attribute of a node will be read.
            _UAAttributeDataPtr AttributeDataPtr = ClientPtr->Read(
                //L"http://opcua.demo-this.com:51211/UA/SampleServer", 
                L"opc.tcp://opcua.demo-this.com:51210/UA/SampleServer",
                L"nsu=http://test.org/UA/Data/ ;i=10853");
    
            // Display results
            _variant_t vString;
            vString.ChangeType(VT_BSTR, &AttributeDataPtr->Value);
            _tprintf(_T("Value: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
            vString.ChangeType(VT_BSTR, &_variant_t(AttributeDataPtr->ServerTimestamp, VT_DATE));
            _tprintf(_T("ServerTimestamp: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
            vString.ChangeType(VT_BSTR, &_variant_t(AttributeDataPtr->SourceTimestamp, VT_DATE));
            _tprintf(_T("SourceTimestamp: %s\n"), (LPCTSTR)CW2CT((_bstr_t)vString));
            _tprintf(_T("StatusCode: %s\n"), (LPCTSTR)CW2CT(AttributeDataPtr->StatusCode->ToString));

            // Example output:
            //
            //Value: -2.230064E-31
            //ServerTimestamp: 11/6/2011 1:34:30 PM
            //SourceTimestamp: 11/6/2011 1:34:30 PM
            //StatusCode: Good

        }
         // Release all interface pointers BEFORE calling CoUninitialize()
        CoUninitialize();
    }
}
// This example shows how to read and display data of an attribute (value,
// timestamps, and status code).

class procedure Read.Main;
var
  Client: EasyUAClient;
  AttributeData: _UAAttributeData;
begin
  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  // Obtain attribute data. By default, the Value attribute of a node will be
  // read.
  AttributeData := Client.Read_(
    //'http://opcua.demo-this.com:51211/UA/SampleServer',
    'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
    'nsu=http://test.org/UA/Data/ ;i=10853');

  // Display results
  WriteLn('Value: ', AttributeData.Value);
  WriteLn('ServerTimestamp: ', DateTimeToStr(AttributeData.ServerTimestamp));
  WriteLn('SourceTimestamp: ', DateTimeToStr(AttributeData.SourceTimestamp));
  WriteLn('StatusCode: ', AttributeData.StatusCode.ToString);

  // Example output:
  //
  //Value: -2.230064E-31
  //ServerTimestamp: 11/6/2011 1:34:30 PM
  //SourceTimestamp: 11/6/2011 1:34:30 PM
  //StatusCode: Good
end;
// This example shows how to read and display data of an attribute (value,
// timestamps, and status code).

class procedure Read.Main;
var
  Client: OpcLabs_EasyOpcUA_TLB._EasyUAClient;
  AttributeData: _UAAttributeData;
begin
  // Instantiate the client object
  Client := CoEasyUAClient.Create;

  // Obtain attribute data. By default, the Value attribute of a node will be
  // read.
  try
    AttributeData := Client.Read(
      //'http://opcua.demo-this.com:51211/UA/SampleServer',
      //'https://opcua.demo-this.com:51212/UA/SampleServer/',
      'opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
      'nsu=http://test.org/UA/Data/ ;i=10853');
  except
    on E: EOleException do
    begin
      WriteLn(Format('*** Failure: %s', [E.GetBaseException.Message]));
      Exit;
    end;
  end;

  // Display results
  WriteLn('Value: ', AttributeData.Value);
  WriteLn('ServerTimestamp: ', DateTimeToStr(AttributeData.ServerTimestamp));
  WriteLn('SourceTimestamp: ', DateTimeToStr(AttributeData.SourceTimestamp));
  WriteLn('StatusCode: ', AttributeData.StatusCode.ToString);

  // Example output:
  //
  //Value: -2.230064E-31
  //ServerTimestamp: 11/6/2011 1:34:30 PM
  //SourceTimestamp: 11/6/2011 1:34:30 PM
  //StatusCode: Good
end;
// This example shows how to read and display data of an attribute (value, timestamps, and status code).

// Instantiate the client object
$Client = new COM("OpcLabs.EasyOpc.UA.EasyUAClient");

// Obtain attribute data. By default, the Value attribute of a node will be read.
try
{
    $AttributeData = $Client->Read(
        //"http://opcua.demo-this.com:51211/UA/SampleServer", 
        "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", 
        "nsu=http://test.org/UA/Data/ ;i=10853");
}
catch (com_exception $e)
{
    printf("*** Failure: %s\n", $e->getMessage());
    Exit();
}

// Display results
printf("Value: %s\n", $AttributeData->Value);
printf("ServerTimestamp: %s\n", $AttributeData->ServerTimestamp);
printf("SourceTimestamp: %s\n", $AttributeData->SourceTimestamp);
printf("StatusCode: %s\n", $AttributeData->StatusCode);

// Example output:
//
//Value: -2.230064E-31
//ServerTimestamp: 11/6/2011 1:34:30 PM
//SourceTimestamp: 11/6/2011 1:34:30 PM
//StatusCode: Good

// This example shows how to read and display data of an attribute (value, timestamps, and status code).

mle_outputtext.Text = ""

// Instantiate the client object
OLEObject client
client = CREATE OLEObject
client.ConnectToNewObject("OpcLabs.EasyOpc.UA.EasyUAClient")

// Obtain attribute data. By default, the Value attribute of a node will be read.
OLEObject attributeData
TRY
    attributeData = client.Read("http://opcua.demo-this.com:51211/UA/SampleServer", "nsu=http://test.org/UA/Data/ ;i=10853")        // or "opc.tcp://opcua.demo-this.com:51210/UA/SampleServer"
CATCH (OLERuntimeError oleRuntimeError)
    mle_outputtext.Text = mle_outputtext.Text + "*** Failure: " + oleRuntimeError.Description + "~r~n"
    RETURN
END TRY

// Display results
mle_outputtext.Text = mle_outputtext.Text + "Value: " + String(attributeData.value) + "~r~n"
mle_outputtext.Text = mle_outputtext.Text + "ServerTimestamp: " + String(attributeData.ServerTimestamp) + "~r~n"
mle_outputtext.Text = mle_outputtext.Text + "SourceTimestamp: " + String(attributeData.SourceTimestamp) + "~r~n"
mle_outputtext.Text = mle_outputtext.Text + "StatusCode: " + String(attributeData.StatusCode) + "~r~n"

// Example output:
//
//Value: -2.230064E-31
//ServerTimestamp: 11/6/2011 1:34:30 PM
//SourceTimestamp: 11/6/2011 1:34:30 PM
//StatusCode: Good

# This example shows how to read and display data of an attribute (value, timestamps, and status code).

# The Python for Windows (pywin32) extensions package is needed. Install it using "pip install pypiwin32".
# CAUTION: We now recommend using Python.NET package instead. Full set of examples with Python.NET is available!
import win32com.client
from pywintypes import com_error

# Instantiate the client object
client = win32com.client.Dispatch('OpcLabs.EasyOpc.UA.EasyUAClient') 

# Obtain attribute data. By default, the Value attribute of a node will be read.
try:
    attributeData = client.Read('opc.tcp://opcua.demo-this.com:51210/UA/SampleServer',
                                'nsu=http://test.org/UA/Data/ ;i=10853')
except com_error as e:
    print('*** Failure: ' + e.args[2][1] + ': ' + e.args[2][2])
    exit()

# Display results
print('Value: ', attributeData.Value)
print('ServerTimestamp: ', attributeData.ServerTimestamp)
print('SourceTimestamp: ', attributeData.SourceTimestamp)
print('StatusCode: ', attributeData.StatusCode)

# Example output:
#
#Value: -2.230064E-31
#ServerTimestamp: 11/6/2011 1:34:30 PM
#SourceTimestamp: 11/6/2011 1:34:30 PM
#StatusCode: Good

Rem This example shows how to read and display data of an attribute (value, timestamps, and status code).

Public Sub Read_Main_Command_Click()
    OutputText = ""

    ' Instantiate the client object
    Dim Client As New EasyUAClient

    ' Obtain attribute data. By default, the Value attribute of a node will be read.
    On Error Resume Next
    Dim AttributeData As UAAttributeData
    Set AttributeData = Client.Read("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", _
                                    "nsu=http://test.org/UA/Data/ ;i=10853")
    If Err.Number <> 0 Then
        OutputText = OutputText & "*** Failure: " & Err.Source & ": " & Err.Description & vbCrLf
        Exit Sub
    End If
    On Error GoTo 0

    ' Display results
    OutputText = OutputText & "Value: " & AttributeData.value & vbCrLf
    OutputText = OutputText & "ServerTimestamp: " & AttributeData.ServerTimestamp & vbCrLf
    OutputText = OutputText & "SourceTimestamp: " & AttributeData.SourceTimestamp & vbCrLf
    OutputText = OutputText & "StatusCode: " & AttributeData.StatusCode & vbCrLf

    ' Example output:
    '
    'Value: -2.230064E-31
    'ServerTimestamp: 11/6/2011 1:34:30 PM
    'SourceTimestamp: 11/6/2011 1:34:30 PM
    'StatusCode: Good
End Sub
Rem This example shows how to read and display data of an attribute (value, timestamps, and status code).

Option Explicit

' Instantiate the client object
Dim Client: Set Client = CreateObject("OpcLabs.EasyOpc.UA.EasyUAClient")

' Obtain attribute data. By default, the Value attribute of a node will be read.
On Error Resume Next
Dim AttributeData: Set AttributeData = Client.Read("opc.tcp://opcua.demo-this.com:51210/UA/SampleServer", _
                                                   "nsu=http://test.org/UA/Data/ ;i=10853")
If Err.Number <> 0 Then
    WScript.Echo "*** Failure: " & Err.Source & ": " & Err.Description
    WScript.Quit
End If
On Error Goto 0

' Display results
WScript.Echo "Value: " & AttributeData.Value
WScript.Echo "ServerTimestamp: " & AttributeData.ServerTimestamp
WScript.Echo "SourceTimestamp: " & AttributeData.SourceTimestamp
WScript.Echo "StatusCode: " & AttributeData.StatusCode

' Example output:
'
'Value: -2.230064E-31
'ServerTimestamp: 11/6/2011 1:34:30 PM
'SourceTimestamp: 11/6/2011 1:34:30 PM
'StatusCode: Good

Tools

:: This example shows how to read and display data of an attribute (value, timestamps, and status code).

:: Invoke the OPC UA client.
uaClient

:: Obtain attribute data and display results. By default, the Value attribute of a node will be read.
read opc.tcp://opcua.demo-this.com:51210/UA/SampleServer "nsu=http://test.org/UA/Data/ ;i=10853"

 

See Also

Conceptual

Examples - OPC Data Access

Examples - OPC UA Interaction

Examples - OPC UA Layered Extensions